function submitForm(){
	$("#baseitemsJson").val(getBaseitemsValue());
	$("#assitemsJson").val(getAssitemsValue());
	document.getElementById("assrecordsForm").action = contextpath+"/biz/contract/assrecord/create";
	document.getElementById("assrecordsForm").submit();
}

//--------------------------------结算条款Js--------------------------------
function showModalBaseitems(id, index, i, flag){
	if(flag == null){
		flag = $("#flag").val();
	}
	var contractType = $("#contractType").val();
	var brandsId = $("#brandsId"+i).val();
	$("#modalAssbaseitems").load(contextpath+"/biz/contract/assrecord/showModalAssbaseitems?brandsId="+brandsId+"&flag="+flag+"&contractType="+contractType,
		function() {$("#modalAssbaseitems").modal("show");});
	setTimeout(function(){
		showModalBaseitemsValue(i);
		$("#updateBaseitemsId").val(i);
	},500);
}

//function showModalBaseitemsJs(id, index, i){
//	$("#modalAssbaseitems").load(contextpath+"/biz/contract/assrecord/showModalAssbaseitems?id=0",
//			function() {$("#modalAssbaseitems").modal("show");});
//	setTimeout(function(){
//		showModalBaseitemsValue(i);
//	},500);
//}

function addRow(index) {
	var flag = true;
	if(index == null){
		index = -1;
		flag = validataBaseItem();
	}
	if(flag != false){
		var i = $("#updateBaseitemsId").val();
		$("#updateBaseitemsId").val("");
		if(i == "" || i == null){
			var brandsId = $("#brandName").find("option:selected").val();
			var brandsName = $("#brandName").find("option:selected").text();
			var isGuarantee = $("#isGuarantee").find("option:selected").val();
			var isGuaranteeText = $("#isGuarantee").find("option:selected").text();
			var guaranteeTypeId = $("#guaranteeType").find("option:selected").val();
			var codeType = $("#codeType").find("option:selected").val();
			var codeTypeName = $("#codeType").find("option:selected").text();
			var deductType_base = $("#deductType_base").find("option:selected").val();
			var deductTypeName = $("#deductType_base").find("option:selected").text();
			var iscommGuarantee = $("#iscommGuarantee").find("option:selected").val();
			var countbase_base = $("#countbase_base").find("option:selected").val();
			var guaranteeAmount = $("#guaranteeAmount").val();
			var lower = $("#lower").val();
			var upper = $("#upper").val();
			var payDate = $("#payDate").val();
			var deductRate = $("#deductRate").val();
			var validType = $("#validType").val();
			var deductType = $("#deductType").val();
			var startDate_base = $("#startDate_base").val();
			var endDate_base = $("#endDate_base").val();
			var remarks= $("#remarks").val();
			var isCompare= $("#isCompare_base").val();
			var assistId="";
			
			var assinfoId = $("#assinfoId").val();
			if(assinfoId == null){
				var status = "00";
				var statusName = "新签";
			}else{
				var status = "01";
				var statusName = "新增";
			}
			
			if(index >= 0){			//用于复制功能
				var isGuarantee = $("#isGuarantee"+index).val();
				var isGuaranteeText = $("#isGuarantee_lab"+index).text();
				var lower = $("#lower"+index).val();
				var upper = $("#upper"+index).val();
				var payDate = $("#payDate"+index).val();
				var deductRate = $("#deductRate"+index).val();
				var brandsId = $("#brandsId"+index).val();
				var validType = $("#validType"+index).val();
				var countbase_base = $("#countbase_base"+index).val();
				var guaranteeTypeId = $("#guaranteeType"+index).val();
				var deductType_base = $("#deductType_base"+index).val();
				var deductTypeName = $("#deductType"+index).text();
				var startDate_base = $("#startDate_base"+index).val();
				var endDate_base = $("#endDate_base"+index).val();
				var iscommGuarantee = $("#iscommGuarantee"+index).val();
				var guaranteeAmount = $("#guaranteeAmount"+index).val();
				var remarks = $("#remarks"+index).val();
				var codeType = $("#codeType"+index).val();
				var isCompare = $("#isCompare"+index).val();
				var codeTypeName = $("#codeType_lab"+index).text();
				var assistId = $("#id"+index).val();
				var status = "02";
				var statusName = "调整";

				$("#status"+index).val("03");		//复制后将原来的条款作废
				$("#status_lab"+index).text("作废");
			}
		
		    var newRow = document.createElement ("tr");  
		    newRow.setAttribute("class", "text-center");
		    var newTd0 = document.createElement ("td");
		    newTd0.setAttribute("class", "text-center");
		    var newTd1 = document.createElement ("td");   
		    newTd1.setAttribute("class", "text-center");
		    var newTd2 = document.createElement ("td");
		    newTd2.setAttribute("class", "text-center");
		    var newTd3 = document.createElement ("td");
		    newTd3.setAttribute("class", "text-center");
		    var newTd4 = document.createElement ("td");
		    newTd4.setAttribute("class", "text-center");
		    var newTd5 = document.createElement ("td");
		    newTd5.setAttribute("class", "text-center");
		    var newTd6 = document.createElement ("td");
		    newTd6.setAttribute("class", "text-center");
		    var newTd7 = document.createElement ("td");
		    newTd7.setAttribute("class", "text-center");
		    var newTd8 = document.createElement ("td");
		    newTd8.setAttribute("class", "text-center");
		    var newTd9 = document.createElement ("td");
		    newTd9.setAttribute("style", "display: none");
		    
		    newTd0.innerHTML = "<label id='isGuarantee_lab"+negAssbaseitemsNum+"'>"+isGuaranteeText+"</label>";
		    newTd1.innerHTML = "<label id='guaranteeAmount_lab"+negAssbaseitemsNum+"'>"+guaranteeAmount+"</label>";
		    newTd2.innerHTML = "<label id='lower_lab"+negAssbaseitemsNum+"'>"+lower+"</label>";
		    newTd3.innerHTML = "<label id='upper_lab"+negAssbaseitemsNum+"'>"+upper+"</label>";
		    newTd4.innerHTML = "<label id='deductRate_lab"+negAssbaseitemsNum+"'>"+deductRate+"</label>";
		    newTd5.innerHTML = "<label id='startDate_lab"+negAssbaseitemsNum+"'>"+startDate_base+"</label>";
		    newTd6.innerHTML = "<label id='endDate_lab"+negAssbaseitemsNum+"'>"+endDate_base+"</label>";
		    newTd7.innerHTML = "<label id='status_lab"+negAssbaseitemsNum+"'>"+statusName+"</label>";
		    newTd8.innerHTML = "<a href='javascript:void(0)' onclick='showModalBaseitems(this, this.parentElement.parentElement.rowIndex,"+negAssbaseitemsNum+")'>修改</a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick='removeFile(this, this.parentElement.parentElement.rowIndex)'>删除</a>&nbsp;&nbsp;<a href='javascript:void(0)' style='color: #e8e8e8'>复制</a></td></tr>";
		    newTd9.innerHTML = "<input type='hidden' id='isGuarantee"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].isGuarantee' value='"+isGuarantee+"'/>" +
							   "<input type='hidden' id='lower"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].lower' value='"+lower+"'/>" +
							   "<input type='hidden' id='upper"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].upper' value='"+upper+"'/>" +
							   "<input type='hidden' id='payDate"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].payDate' value='"+payDate+"'/>" +
							   "<input type='hidden' id='deductRate"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].deductRate' value='"+deductRate+"'/>" +
							   "<input type='hidden' id='brandsId"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].brandsId' value='"+brandsId+"'/>" +
							   "<input type='hidden' id='validType"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].validType' value='"+validType+"'/>" +
							   "<input type='hidden' id='countbase_base"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].countBase' value='"+countbase_base+"'/>" +
							   "<input type='hidden' id='guaranteeType"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].guaranteeType' value='"+guaranteeTypeId+"'/>" +
							   "<input type='hidden' id='codeType"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].codeType' value='"+codeType+"'/>" +
							   "<input type='hidden' id='deductType_base"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].deductType' value='"+deductType_base+"'/>" +
							   "<input type='hidden' id='startDate_base"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].startDate' value='"+startDate_base+"'/>" +
							   "<input type='hidden' id='endDate_base"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].endDate' value='"+endDate_base+"'/>" +
							   "<input type='hidden' id='iscommGuarantee"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].iscommGuarantee' value='"+iscommGuarantee+"'/>" +
							   "<input type='hidden' id='guaranteeAmount"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].guaranteeAmount' value='"+guaranteeAmount+"'/>" +
							   "<input type='hidden' id='isCompare"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].isCompare' value='"+isCompare+"'/>" +
							   "<input type='hidden' id='assistId"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].assistId' value='"+assistId+"'/>" +
							   "<input type='hidden' id='status"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].status' value='"+status+"'/>" +
							   "<input type='hidden' id='remarks"+negAssbaseitemsNum+"' name='negAssbaseitems["+negAssbaseitemsNum+"].remarks' value='"+isGuarantee+"' />";
		    newRow.appendChild (newTd0);     
		    newRow.appendChild (newTd1);
		    newRow.appendChild (newTd2);
		    newRow.appendChild (newTd3);
		    newRow.appendChild (newTd4);  
		    newRow.appendChild (newTd5);  
		    newRow.appendChild (newTd6);  
		    newRow.appendChild (newTd7);  
		    newRow.appendChild (newTd8);  
		    newRow.appendChild (newTd9);  
		    document.getElementById("tbody").appendChild (newRow);
		    assbaseitemList.push(negAssbaseitemsNum);
		    negAssbaseitemsNum++;
		}else{
			updateRowByBaseitems(i);
		}
		$("#baseitems_ok").attr("data-dismiss", "modal");
	}
}

function status_zf(index){
	$("#status"+index).val("03");		
	$("#status_lab"+index).text("作废");
	$("#cancel").css("color", "#e8e8e8");
}

function showModalBaseitemsValue(i){
	$("#isGuarantee").val($("#isGuarantee"+i).val());
	$("#guaranteeType").val($("#guaranteeType"+i).val());
	$("#guaranteeAmount").val($("#guaranteeAmount"+i).val());
	$("#deductType_base").val($("#deductType_base"+i).val());
	$("#codeType").val($("#codeType"+i).val());
	$("#guaranteeProfit").val($("#guaranteeProfit"+i).val());
	$("#iscommGuarantee").val($("#iscommGuarantee"+i).val());
	$("#countbase_base").val($("#countbase_base"+i).val());
	$("#lower").val($("#lower"+i).val());
	$("#upper").val($("#upper"+i).val());
	$("#payDate").val($("#payDate"+i).val());
	$("#deductRate").val($("#deductRate"+i).val());
	$("#brandsId").val($("#brandsId"+i).val());
	$("#validType").val($("#validType"+i).val());
	$("#startDate_base").val($("#startDate_base"+i).val());
	$("#endDate_base").val($("#endDate_base"+i).val());
	$("#isCompare_base").val($("#isCompare"+i).val());
	$("#remarks").val($("#remarks"+i).val());
	$("#updateBaseitemsId").val(i);
	
	if($("#isGuarantee").val() == "1"){		//如何结算条款选择的是保底。则保底形式、保底金额等可以填写
		$("#guaranteeType").removeAttr("disabled");
		$("#guaranteeAmount").removeAttr("disabled");
		$("#iscommGuarantee").removeAttr("disabled");
		$("#countbase_base").removeAttr("disabled");
	}
	if(i==null){
		$("#startDate_base").val($("#startDate").val());
		$("#endDate_base").val($("#endDate").val());
	}
}

function updateRowByBaseitems(j) {
	$("#isGuarantee_lab"+j).text($("#isGuarantee").find("option:selected").text());
	$("#guaranteeAmount_lab"+j).text($("#guaranteeAmount").val());
	$("#upper_lab"+j).text( $("#upper").val());
	$("#lower_lab"+j).text($("#lower").val());
	$("#deductRate_lab"+j).text($("#deductRate").val());
	$("#startDate_lab"+j).text($("#startDate_base").val());
	$("#endDate_lab"+j).text($("#endDate_base").val());
	
	$("#isGuarantee"+j).val($("#isGuarantee").val());
	$("#isCompare"+j).val($("#isCompare_base").val());
	$("#guaranteeType"+j).val($("#guaranteeType option:selected").val());
	$("#codeType"+j).val($("#codeType option:selected").val());
	$("#deductType_base"+j).val($("#deductType_base option:selected").val());
	$("#deductType"+j).text($("#deductType_base option:selected").text());
	$("#guaranteeAmount"+j).val($("#guaranteeAmount").val());
	$("#guaranteeProfit"+j).val($("#guaranteeProfit").val());
	$("#lower"+j).val($("#lower").val());
	$("#upper"+j).val($("#upper").val());
	$("#payDate"+j).val($("#payDate").val());
	$("#deductRate"+j).val($("#deductRate").val());
	$("#brandsId"+j).val($("#brandName").find("option:selected").val());
	$("#iscommGuarantee"+j).val($("#iscommGuarantee").find("option:selected").val());
	$("#countbase_base"+j).val($("#countbase_base").find("option:selected").val());
	$("#validType"+j).val($("#validType").val());
	$("#startDate_base"+j).val($("#startDate_base").val());
	$("#endDate_base"+j).val($("#endDate_base").val());
	$("#countBase"+j).val($("#countBase").val());
	$("#remarks"+j).val($("#remarks").val());
}

function getBaseitemsValue(){
	var jsonStr = "";
	jsonStr = "[";
	for(var i=0; i< list.length; i++){
		var guaranteeType = $("#guaranteeType"+list[i]).text();
		var guaranteeAmount = $("#guaranteeAmount"+list[i]).text();
		var guaranteeProfit = $("#guaranteeProfit"+list[i]).text();
		var isGuarantee = $("#isGuarantee"+list[i]).text();
		var lower = $("#lower"+list[i]).text();
		var upper = $("#upper"+list[i]).text();
		var payDate = $("#payDate"+list[i]).text();
		var deductRate = $("#deductRate"+list[i]).text();
		var brandsId = $("#brandsId"+list[i]).text();
		var validType = $("#validType"+list[i]).text();
		var deductType = $("#deductType"+list[i]).text();
		var countBase= $("#countBase"+list[i]).text();
		var remarks= $("#remarks"+list[i]).text();
		
		jsonStr += "{'guaranteeType':'"+guaranteeType+"', 'guaranteeAmount':'"+guaranteeAmount+"', 'guaranteeProfit':'"+guaranteeProfit+"', 'isGuarantee':'"+isGuarantee+"', " +
				    "'lower':'"+lower+"', 'upper':'"+upper+"', 'payDate':'"+payDate+"', 'deductRate':'"+deductRate+"', 'brandsId':'"+brandsId+"', 'validType':'"+validType+"', " +
				    "'deductType':'"+deductType+"', 'countBase':'"+countBase+"', 'remarks':'"+remarks+"'}";
		if(i < list.length-1){
			jsonStr +=",";
		}
	}
	jsonStr += "]";
	return jsonStr;
}

function removeFile(id, index) {
    var tr=id.parentNode.parentNode;  
    var tbody=tr.parentNode;  
    tbody.removeChild(tr);
    assbaseitemList.splice(index-1, 1);
} 
//--------------------------------结算条款Js结束--------------------------------



//--------------------------------合同条款Js------------------------------------
function showModalAssitems(index, i, flag){
	if(flag == null){
		flag = $("#flag").val();
	}
	var contractType = $("#contractType").val();
	var deductCode = $("#deductCode"+i).val();
	$("#modalAssitems").load(contextpath+"/biz/contract/assrecord/showModalAssitems?deductCode="+deductCode+"&flag="+flag+"&contractType="+contractType,
		function() {
			$("#modalAssitems").modal("show");
		});
	setTimeout(function(){
		showModalAssitemsValue(i);
		$("#updateAssitemsId").val(i);
	},500);
}

function addAssitemsRow() {
	var flag = validataItems();
	var pix ='';
	if(flag != false){
		var i = $("#updateAssitemsId").val();
		$("#updateAssitemsId").val("");
		if(i == ""){
			var deductCode = $("#deductCode").val();
	
			 if(deductCode.substring(0,1)=='A'){
				 pix='%'
			  }
			var deductItem = $("#deductItem").val();
			var deductCateName = $("#deductCate option:selected").text();
			var deductCate =  $("#deductCate option:selected").val();
			var taxRateCode_items =  $("#taxRateCode_items option:selected").val();
			var taxRateCode_items_name =  $("#taxRateCode_items option:selected").val();
			var amount = $("#amount").val();		
			var startDate = $("#assItemsStartDate").val();
			var endDate = $("#assItemsEndDate").val();
			var assItemsValidType = $("#assItemsValidType").val();
			var assItemsValidTypeText = $("#assItemsValidType").find("option:selected").text();
			var assItemsCountBase = $("#assItemsCountBase").val();
			var assItemsCountBaseText = $("#assItemsCountBase").find("option:selected").text();
			var assItemsDeductType = $("#assItemsDeductType").val();
			var assItemsTaxRate = $("#taxRateCode_items").val();
			var assItemsTaxRateText = $("#taxRateCode_items").find("option:selected").text();
			var assItemsRemarks = $("#assItemsRemarks").val();
		
		    var newRow = document.createElement ("tr");  
		    newRow.setAttribute("class", "text-center");
		    var newTd0 = document.createElement ("td");
		    newTd0.setAttribute("class", "text-center");
		    var newTd1 = document.createElement ("td");   
		    newTd1.setAttribute("class", "text-center");
		    var newTd2 = document.createElement ("td");
		    newTd2.setAttribute("class", "text-center");
		    var newTd3 = document.createElement ("td");
		    newTd3.setAttribute("class", "text-center");
		    var newTd4 = document.createElement ("td");
		    newTd4.setAttribute("class", "text-center");
		    var newTd5 = document.createElement ("td");
		    newTd5.setAttribute("class", "text-center");
		    var newTd6 = document.createElement ("td");
		    newTd6.setAttribute("class", "text-center");
		    var newTd7 = document.createElement ("td");
		    newTd7.setAttribute("class", "text-center");
		    var newTd8 = document.createElement ("td");
		    newTd8.setAttribute("class", "text-center");
		    var newTd9 = document.createElement ("td");
		    newTd9.style="display: none";
		   
		    newTd0.innerHTML = "<label id='deductCode_lab"+negAssitemsNum+"'>"+deductCode+"</label>";
		    newTd1.innerHTML = "<label id='deductItem_lab"+negAssitemsNum+"'>"+deductItem+"</label>";
		    newTd2.innerHTML = "<label id='amount_lab"+negAssitemsNum+"'>"+amount+pix+"</label>";		
		    newTd3.innerHTML = "<label id='startDate_lab"+negAssitemsNum+"'>"+startDate+"</label>";		
		    newTd4.innerHTML = "<label id='endDate_lab"+negAssitemsNum+"'>"+endDate+"</label>";		
		    newTd5.innerHTML = "<label id='deductCate_lab"+negAssitemsNum+"'>"+assItemsValidTypeText+"</label>";		
		    newTd6.innerHTML = "<label id='countBase_lab"+negAssitemsNum+"'>"+assItemsCountBaseText+"</label>";		
		    newTd7.innerHTML = "<label id='taxRate_lab"+negAssitemsNum+"'>"+assItemsTaxRateText+"</label>";		
		    newTd8.innerHTML = "<a href='javascript:void(0)' onclick='showModalAssitems(this.parentElement.parentElement.rowIndex,"+negAssitemsNum+")'>修改</a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick='removeAssitemsRow(this, this.parentElement.parentElement.rowIndex)'>删除</a></td></tr>";
		    newTd9.innerHTML =  "<input type='hidden' id='deductCode"+negAssitemsNum+"' name='negAssitems["+negAssitemsNum+"].deductCode' value="+deductCode+"></input>" +
							    "<input type='hidden' id='assItemsStartDate"+negAssitemsNum+"' name='negAssitems["+negAssitemsNum+"].startDate' value="+startDate+"></input>" +
							    "<input type='hidden' id='assItemsEndDate"+negAssitemsNum+"' name='negAssitems["+negAssitemsNum+"].endDate' value="+endDate+"></input>" +
							    "<input type='hidden' id='assItemsValidType"+negAssitemsNum+"' name='negAssitems["+negAssitemsNum+"].validType' value="+assItemsValidType+"></input>" +
							    "<input type='hidden' id='assItemsCountBase"+negAssitemsNum+"' name='negAssitems["+negAssitemsNum+"].countBase' value="+assItemsCountBase+"></input>" +
							    "<input type='hidden' id='assItemsDeductType"+negAssitemsNum+"' name='negAssitems["+negAssitemsNum+"].deductType' value="+assItemsDeductType+"></input>" +
							    "<input type='hidden' id='assItemsTaxRate"+negAssitemsNum+"' name='negAssitems["+negAssitemsNum+"].taxRate' value="+assItemsTaxRate+"></input>" +
							    "<input type='hidden' id='deductItem"+negAssitemsNum+"' name='negAssitems["+negAssitemsNum+"].deductItem' value="+deductItem+"></input>" +
							    "<input type='hidden' id='deductCate"+negAssitemsNum+"' name='negAssitems["+negAssitemsNum+"].deductCate' value="+deductCate+"></input>" +
							    "<input type='hidden' id='amount"+negAssitemsNum+"' name='negAssitems["+negAssitemsNum+"].amount' value="+amount+"></input>" +
							    "<input type='hidden' id='taxRateCode_items"+negAssitemsNum+"' name='negAssitems["+negAssitemsNum+"].taxRate' value="+taxRateCode_items+"></input>" +
							    "<input type='hidden' id='assItemsRemarks"+negAssitemsNum+"' name='negAssitems["+negAssitemsNum+"].remarks' value="+assItemsRemarks+"></input>";
		    newRow.appendChild (newTd0);     
		    newRow.appendChild (newTd1);
		    newRow.appendChild (newTd2);
		    newRow.appendChild (newTd3);
		    newRow.appendChild (newTd4);  
		    newRow.appendChild (newTd5);  
		    newRow.appendChild (newTd6);  
		    newRow.appendChild (newTd7);  
		    newRow.appendChild (newTd8);  
		    newRow.appendChild (newTd9);  
		    document.getElementById("assitemsTbody").appendChild (newRow);
		    assitemsList.push(negAssitemsNum);
		    negAssitemsNum++;
		}else{
			updateRowByAssitems(i);
		}
		 $('#deductCode', this).chosen('destroy').chosen();
		$("#items_ok").attr("data-dismiss","modal");
	}
}

//function showModalAssitemsJs(id, index, i){
//	$("#modalAssitems").load(contextpath+"/biz/contract/assrecord/showModalAssitems?id=0",
//			function() {$("#modalAssitems").modal("show");});
//	setTimeout(function(){
//		showModalAssitemsValue(i);
//		$("#updateAssitemsId").val(i);
//	},500);
//}

function showModalAssitemsValue(i){
	var deductCode = $("#deductCode"+i).val();
	$("#deductCode").val(deductCode);
	$("#deductItem").val($("#deductItem"+i).val());
	$("#deductCate").val($("#deductCate"+i).val());
	$("#amount").val($("#amount"+i).val());
	$("#assItemsStartDate").val($("#assItemsStartDate"+i).val());
	$("#assItemsEndDate").val($("#assItemsEndDate"+i).val());
	if($("#assItemsValidType"+i).val()!=null){
		$("#assItemsValidType").val($("#assItemsValidType"+i).val());
	}
	if($("#assItemsDeductType"+i).val()!=null){
		$("#assItemsDeductType").val($("#assItemsDeductType"+i).val());
	}
	$("#assItemsCountBase").val($("#assItemsCountBase"+i).val());
	$("#assItemsTaxRate").val($("#assItemsTaxRate"+i).val());
	$("#assItemsRemarks").val($("#assItemsRemarks"+i).val());
	var taxRateCode_items = $("#taxRateCode_items"+i).val();
	var shopId=$("#storeId").val();
	$("#taxRateCode_items").FillOptions(Com_Parameter.ContextPath+"/sys/base/article/getSysBaseRateCode?itemNum="+deductCode+"&shopId="+shopId,{datatype:"json",textfield:"articleName",valuefiled:"article",defValue:taxRateCode_items});
	if(i==null){
		$("#assItemsStartDate").val($("#startDate").val());
		$("#assItemsEndDate").val($("#endDate").val());
	}
}

function updateRowByAssitems(j) {
	$("#deductCode_lab"+j).text($("#deductCode").val());
	$("#deductItem_lab"+j).text($("#deductItem").val());
	var amount =$("#amount").val();
	var pix =$("#deductCode").val().substring(0,1)=='A'?'%':'';
	$("#amount_lab"+j).text(amount+pix);
	$("#startDate_lab"+j).text($("#assItemsStartDate").val());
	$("#endDate_lab"+j).text($("#assItemsEndDate").val());
	$("#deductCate_lab"+j).text($("#assItemsValidType").find("option:selected").text());
	$("#countBase_lab"+j).text($("#assItemsCountBase").find("option:selected").text());
	$("#taxRate_lab"+j).text($("#taxRateCode_items").find("option:selected").text());
	$("#deductCode"+j).val($("#deductCode").val());
	$("#deductItem"+j).val($("#deductItem").val());
	$("#taxRateCode_items"+j).val($("#taxRateCode_items").find("option:selected").val());
	$("#deductCate"+j).val($("#deductCate").val());
	$("#amount"+j).val($("#amount").val());
	$("#assItemsStartDate"+j).val($("#assItemsStartDate").val());
	$("#assItemsEndDate"+j).val($("#assItemsEndDate").val());
	$("#assItemsValidType"+j).val($("#assItemsValidType").val());
	$("#assItemsCountBase"+j).val($("#assItemsCountBase").val());
	$("#assItemsDeductType"+j).val($("#assItemsDeductType").val());
	$("#assItemsTaxRate"+j).val($("#assItemsTaxRate").val());
	$("#assItemsRemarks"+j).val($("#assItemsRemarks").val());
}

function getAssitemsValue(){
	var jsonStr = "";
	jsonStr = "[";
	for(var i=0; i< assitemsList.length; i++){
		var deductCode = $("#deductCode"+assitemsList[i]).val();
		var deductItem = $("#deductItem"+assitemsList[i]).val();
		var deductCate = $("#deductCate"+assitemsList[i]).val();
		var amount = $("#amount"+assitemsList[i]).val();
		var startDate = $("#assItemsStartDate"+assitemsList[i]).val();
		var endDate = $("#assItemsEndDate"+assitemsList[i]).val();
		var assItemsValidType = $("#assItemsValidType"+assitemsList[i]).val();
		var assItemsCountBase = $("#assItemsCountBase"+assitemsList[i]).val();
		var assItemsDeductType = $("#assItemsDeductType"+assitemsList[i]).val();
		var assItemsTaxRate = $("#assItemsTaxRate"+assitemsList[i]).val();
		var assItemsRemarks = $("#assItemsRemarks"+assitemsList[i]).val();
		
		jsonStr += "{'deductCode':'"+deductCode+"', 'deductItem':'"+deductItem+"', 'deductCate':'"+deductCate+"', 'amount':'"+amount+"', " +
				    "'startDate':'"+startDate+"', 'endDate':'"+endDate+"', 'validType':'"+assItemsValidType+"', 'countBase':'"+assItemsCountBase+"', " +
				    "'deductType':'"+assItemsDeductType+"', 'taxRate':'"+assItemsTaxRate+"', " +
				    "'remarks':'"+assItemsRemarks+"'}";
		if(i < assitemsList.length-1){
			jsonStr +=",";
		}
	}
	jsonStr += "]";
	return jsonStr;
}

function removeAssitemsRow(id, index) {
    var tr=id.parentNode.parentNode;  
    var tbody=tr.parentNode;  
    tbody.removeChild(tr);
    assitemsList.splice(index-1, 1);
} 
//---------------------------合同条款Js结束---------------------------------------


//---------------------------合同品牌Js---------------------------------------
//function showModalBrand(id, index, assitemsId, i){
//	var brandId = $("#brandId"+i).val();
//	var supplierNo = $("#supplierNo").val();
//	if(assitemsId == null)
//		assitemsId = 0;
//	$("#modalBrand").load(contextpath+"/biz/contract/assrecord/showModalAssBrand?brandId"+brandId+"&supplierNo="+supplierNo,
//		function() {$("#modalBrand").modal("show");});
//	setTimeout(function(){
//		showModalBrandValue(i);
//		isMainBrand();		//处理主品牌只能选择一次
//		$("#updateBrandId").val(i);
//	},500);
//}

function showModalBrand(id, index, i){
	if ($("#supplierNo").val() == "") {
		$("#supplierNo").focus();
		top.$.jBox.tip('请选择供应商', 'warning');
		return false;
	}
	var inviteCate = $("#inviteCate"+i).val();
	var brandId = $("#brandId"+i).val();
	var supplierNo = $("#supplierNo").val();
	var brandNo = $("#brand_No").val();
	var flag = $("#flag").val();
	var iszs = $("#iszs"+i).val();
	if(iszs == null){
		iszs="";
	}
	$("#modalBrand").load(contextpath+"/biz/contract/assrecord/showModalAssBrand?brandId"+brandId+"&supplierNo="+supplierNo+"&inviteCate="+inviteCate+"&flag="+flag+"&brandNo="+brandNo+"&iszs="+iszs,
			function() {$("#modalBrand").modal("show");});
	setTimeout(function(){
		showModalBrandValue(i);
		isMainBrand();		//处理主品牌只能选择一次
		$("#updateBrandId").val(i);
	},1000);
}

function addBrandRow() {
	var flag = validataBrand();
	if(flag != false){			//表单验证通过在执行操作
		var i = $("#updateBrandId").val();
		$("#updateBrandId").val("");
		if(i == ""){
			var brandId = $("#brandId").attr("value");
			var brandNo = $("#brandNo").attr("value");
			var brandCname = $("#brandCName").attr("value");
			var brandename = $("#brandEName").attr("value");
			var brandLevel = $("#brandLevel").attr("value");
			var brandAttribute = $("#brandAttribute").attr("value");
			var brandAttributeName = $("#brandAttribute").find("option:selected").text();
			var brandInviteHead = $("#brandInviteHead").attr("value");
			var commodityCate = $("#commodityCate").attr("value");
			var inviteCate = $("#inviteCate").attr("value");
			var inviteCateName = $("#inviteCateName").attr("value");
			var shopName = $("#shopName").attr("value");
			var shopId = $("#assShopIds").val();
			var assbrand_id = $("#assbrand_id").attr("value");
			var memberRateType = $("#memberRateType").attr("value");
			var gcardDiscount = $("#gcardDiscount").attr("value");
			var gcardDiscount2 = $("#gcardDiscount2").attr("value");
			var ocardDiscount2 = $("#ocardDiscount2").attr("value");
			var ocardDiscount = $("#ocardDiscount").attr("value");
			var mainBrands = $("#mainBarnd").attr("value");
			var mainBrandsText = $("#mainBarnd").find("option:selected").text();
			var purchasingGroup = $("#purchasingGroup").attr("value");
			var brand_iszs = $("input[name='brand_iszs']:checked").val();
		
		    var newRow = document.createElement ("tr");  
		    newRow.setAttribute("class", "text-center");
		    var newTd0 = document.createElement ("td");
		    newTd0.setAttribute("class", "text-center");
		    var newTd1 = document.createElement ("td");   
		    newTd1.setAttribute("class", "text-center");
		    var newTd2 = document.createElement ("td");
		    newTd2.setAttribute("class", "text-center");
		    var newTd3 = document.createElement ("td");
		    newTd3.setAttribute("class", "text-center");
		    var newTd4 = document.createElement ("td");
		    newTd4.setAttribute("class", "text-center");
		    var newTd5 = document.createElement ("td");
		    newTd5.setAttribute("class", "text-center");
		    var newTd6 = document.createElement ("td");
		    newTd6.style="display: none";
		    
		    newTd0.innerHTML = "<label id='brandCname_label"+num+"'>"+brandCname+"</label>";
		    newTd1.innerHTML = "<label id='inviteCate_label"+num+"'>"+brandename+"</label>";
		    newTd2.innerHTML = "<label id='mainBrands_label"+num+"'>"+inviteCateName+"</label>";
		    newTd3.innerHTML = "<label id='brandInviteHead_label"+num+"'>"+brandInviteHead+"</label>";
		    newTd4.innerHTML = "<label id='shop_label"+num+"'>"+shopName+"</label>";
		    newTd5.innerHTML = "<a href='javascript:void(0)' onclick='showModalBrand(this, this.parentElement.parentElement.rowIndex,"+num+")'>修改</a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick='removeAssBrandRow(this, this.parentElement.parentElement.rowIndex)'>删除</a></td></tr>";
		    newTd6.innerHTML = "<input type='hidden' id='brandId"+num+"' name='negAssbrands["+num+"].brandId' value='"+brandId+"' />" +
							   "<input type='hidden' id='inviteCate"+num+"' name='negAssbrands["+num+"].inviteCate' value='"+inviteCate+"' />" +
							   "<input type='hidden' id='inviteCateName"+num+"' name='negAssbrands["+num+"].inviteCateName' value='"+inviteCateName+"' />" +
							   "<input type='hidden' id='memberRateType"+num+"' name='negAssbrands["+num+"].memberRateType' value='"+memberRateType+"' />" +
							   "<input type='hidden' id='gcardDiscount"+num+"' name='negAssbrands["+num+"].gcardDiscount' value='"+gcardDiscount+"' />" +
							   "<input type='hidden' id='gcardDiscount2"+num+"' name='negAssbrands["+num+"].gcardDiscount2' value='"+gcardDiscount2+"' />" +
							   "<input type='hidden' id='ocardDiscount"+num+"' name='negAssbrands["+num+"].ocardDiscount' value='"+ocardDiscount+"' />" +
							   "<input type='hidden' id='ocardDiscount2"+num+"' name='negAssbrands["+num+"].ocardDiscount2' value='"+ocardDiscount2+"' />" +
							   "<input type='hidden' id='mainBarnd"+num+"' name='negAssbrands["+num+"].mainBrands' value='"+mainBrands+"' />" +
							   "<input type='hidden' id='brandNo"+num+"' name='negAssbrands["+num+"].brandNo' value='"+brandNo+"' />" +
							   "<input type='hidden' id='brandCname"+num+"' name='negAssbrands["+num+"].brandCname' value='"+brandCname+"' />" +
							   "<input type='hidden' id='brandename"+num+"' name='negAssbrands["+num+"].brandename' value='"+brandename+"' />" +
							   "<input type='hidden' id='brandAttribute"+num+"' name='negAssbrands["+num+"].brandAttribute' value='"+brandAttribute+"' />" +
							   "<input type='hidden' id='brandLevel"+num+"' name='negAssbrands["+num+"].brandLevel' value='"+brandLevel+"' />" +
							   "<input type='hidden' id='commodityCate1"+num+"' name='negAssbrands["+num+"].commodityCate1' value='"+commodityCate+"' />" +
							   "<input type='hidden' id='shopNames"+num+"' name='negAssbrands["+num+"].shopNames' value='"+shopName+"' />" +
							   "<input type='hidden' id='assShopIds"+num+"' name='negAssbrands["+num+"].shopIds' value='"+shopId+"' />" +
							   "<input type='hidden' id='brandInviteHead"+num+"' name='negAssbrands["+num+"].brandInviteHead' value='"+brandInviteHead+"' />" +
		    				   "<input type='hidden' id='iszs"+num+"' name='negAssbrands["+num+"].iszs' value='"+brand_iszs+"' />";
		    newRow.appendChild (newTd0);     
		    newRow.appendChild (newTd1);
		    newRow.appendChild (newTd2);
		    newRow.appendChild (newTd3);
		    newRow.appendChild (newTd4);  
		    newRow.appendChild (newTd5);  
		    newRow.appendChild (newTd6);  
		    document.getElementById("assBrandTbody").appendChild (newRow);
		    assBrandList.push(num);
		    num++;
		}else{
			updateRowByBrand(i);
		}
		$("#brand_ok").attr("data-dismiss", "modal");
	}
}

function showModalBrandValue(i){
	var brandId = $("#brandId"+i).val();
	$("#brand").val(brandId);
	$("#brandId").val(brandId);
	$("#mainBarnd").val($("#mainBarnd"+i).val());
	$("#inviteCate").val($("#inviteCate"+i).val());
	$("#memberRateType").val($("#memberRateType"+i).val());
	$("#gcardDiscount").val($("#gcardDiscount"+i).val());
	$("#gcardDiscount2").val($("#gcardDiscount2"+i).val());
	$("#ocardDiscount").val($("#ocardDiscount"+i).val());
	$("#ocardDiscount2").val($("#ocardDiscount2"+i).val());
	$("#mainBarnd").val($("#mainBarnd"+i).val());
	$("#brandNo").val($("#brandNo"+i).val());
	$("#brandCName").val($("#brandCname"+i).val());
	$("#brandEName").val($("#brandename"+i).val());
	$("#brandAttribute").val($("#brandAttribute"+i).val());
	$("#brandLevel").val($("#brandLevel"+i).val());
	$("#commodityCate").val($("#commodityCate"+i).val());
	$("#shopName").val($("#assShopIds"+i).val());
	$("#assShopIds").val($("#assShopIds"+i).val());
	$("#brandInviteHead").val($("#brandInviteHead"+i).val());
	$("#brand_iszs").val($("#iszs"+i).val());
	
	if ($("#memberRateType").val() == "20") {
		$("#gcardDiscount").removeAttr("disabled");
		$("#ocardDiscount").removeAttr("disabled");
	}
}

function updateRowByBrand(j) {
	$("#brandCname_label"+j).text($("#brandCName").attr("value"));
	$("#inviteCate_label"+j).text($("#brandEName").val());
	$("#mainBrands_label"+j).text($("#inviteCateName").val());
	$("#brandInviteHead_label"+j).text($("#brandInviteHead").val());
	$("#shop_label"+j).text($("#shopName").val());
	
	$("#brand"+j).val($("#brand").val());
	$("#brandId"+j).val($("#brandId").val());
	$("#mainBarnd"+j).val($("#mainBarnd").val());
	$("#inviteCate"+j).val($("#inviteCate").val());
	$("#inviteCateName"+j).val($("#inviteCateName").val());
	$("#memberRateType"+j).val($("#memberRateType").val());
	$("#gcardDiscount"+j).val($("#gcardDiscount").val());
	$("#gcardDiscount2"+j).val($("#gcardDiscount2").val());
	$("#ocardDiscount"+j).val($("#ocardDiscount").val());
	$("#ocardDiscount2"+j).val($("#ocardDiscount2").val());
	$("#mainBarnd"+j).val($("#mainBarnd").val());
	$("#brandename"+j).val($("#brandEName").val());
	$("#brandAttribute"+j).val($("#brandAttribute").val());
	$("#brandLevel"+j).val($("#brandLevel").val());
	$("#commodityCate"+j).val($("#commodityCate").val());
	$("#shopNames"+j).val($("#shopName").val());
	$("#assShopIds"+j).val($("#assShopIds").val());
	$("#brandInviteHead"+j).val($("#brandInviteHead").val());
	$("#iszs"+j).val($("input[name='brand_iszs']:checked").val());
}

function removeAssBrandRow(id, index) {
    var tr=id.parentNode.parentNode;  
    var tbody=tr.parentNode;  
    tbody.removeChild(tr);
    assBrandList.splice(index-1, 1);
} 


//----------------------------临时扣款项 ----------------------------
function add_hidden(tId, tList) {
	var tr = $(tId).clone();
	var table = $(tId).closest("table");
	// 替换所有的hidden，方便spring的form绑定
	var inputs = tr.find("input");
	var selects = tr.find("select");
	if (tId == "#hidden_contact") {
		max_tr_contact++;
	}
	inputs.each(function() {
		if (tId == "#hidden_contact") {
			this.id = tList + max_tr_contact + this.id;
			this.name = tList + "[" + max_tr_contact + "]" + this.name;
			$(this).attr("data_index", "" + max_tr_contact + "");
		}

	});
	selects.each(function() {
		if (tId == "#hidden_contact") {
			var select = this;
			var ui = $(this);
			if (this.id == '.itemCode') {
				ui.FillOptions(Com_Parameter.ContextPath
						+ "/sys/base/spfItem/getSpecificItems", {
					datatype : "json",
					textfield : "itemName",
					valuefiled : "itemNum"
				});
			}
			this.id = tList + max_tr_contact + this.id;
			this.name = tList + "[" + max_tr_contact + "]" + this.name;
			$(this).attr("data_index", "" + max_tr_contact + "");
		}

	});
	tr.show();
	table.append(tr);
}

function delete_tr(t, dList) {
	var tr = $(t).closest("tr");
	var intputss = tr.find("input :first")
	var id = tr.find("input :first").val();
	if (id != 0) {
		var val = $(dList).val();
		if (val == "") {
			$(dList).val(id);
		} else {
			$(dList).val(val + "," + id);
		}
	}
	tr.remove();

}

function changeItem(tr1, t, value, text) {
	var tr = $(t).closest("tr");
	var cid = "";
	var selects = tr.find("select");
	selects.each(function() {
		var index = $(this).attr("data_index");
		var kid = 'negAssTempItemCodeList' + index + '.remark';
		var remarkUi = tr.find("input");
		remarkUi.each(function() {
			if (this.id == kid) {
				this.value = text;
			}

		});
		var cid = 'negAssTempItemCodeList' + index + '.conditions';
		if (this.id == cid) {
			var ui = $(this);
			ui.FillOptions(Com_Parameter.ContextPath
					+ "/sys/base/spfItem/getConditions?sptNum=" + value, {
				datatype : "json",
				textfield : "value",
				valuefiled : "key"
			});
		}
	});
}


function validataAdd(){
	if ($("#area").val() == "") {
		$("#area").focus();
		top.$.jBox.tip('管理区域不能为空', 'warning');
		return false;
	}
	if ($("#storeId").val() == "") {
		$("#storeId").focus();
		top.$.jBox.tip('签约门店不能为空', 'warning');
		return false;
	}
	if ($("#floorId").val() == "") {
		$("#floorId").focus();
		top.$.jBox.tip('签约楼层不能为空', 'warning');
		return false;
	}
	if ($("#shopIds").val() == "") {
		$("#shopIds").focus();
		top.$.jBox.tip('签约商铺不能为空', 'warning');
		return false;
	}
	if ($("#areaCoefficient").val() == "") {
		$("#areaCoefficient").focus();
		top.$.jBox.tip('面积分摊系数不能为空', 'warning');
		return false;
	}
	if ($("#settlementCycle").val() == "") {
		$("#settlementCycle").focus();
		top.$.jBox.tip('请选择结算周期', 'warning');
		return false;
	}
	if ($("#taxRateCode").val() == "") {
		$("#taxRateCode").focus();
		top.$.jBox.tip('税率不能为空', 'warning');
		return false;
	}
//	if ($("#salesAmount").val() == "") {
//		$("#salesAmount").focus();
//		top.$.jBox.tip('目标销售额不能为空', 'warning');
//		return false;
//	}
	if ($("#paymentType").val() == "") {
		$("#paymentType").focus();
		top.$.jBox.tip('请选择付款方式', 'warning');
		return false;
	}
	if ($("#supplierNo").val() == "") {
		$("#supplierNo").focus();
		top.$.jBox.tip('请选择供应商', 'warning');
		return false;
	}
	if ($("#startDate").val() == "") {
		$("#startDate").focus();
		top.$.jBox.tip('合同起始日期不能为空', 'warning');
		return false;
	}
	if ($("#endDate").val() == "") {
		$("#endDate").focus();
		top.$.jBox.tip('合同结束日期不能为空', 'warning');
		return false;
	}
	var contractType = $("#contractType").val();
	if(contractType != "Z500"){
		if ($("input[name='checkoutType']:checked").val() == null) {
			top.$.jBox.tip('请选择收银方式', 'warning');
			return false;
		}
	}
	
//	var negType1 = $("#negType").val();
//	if(negType1 == "20"){
//		if ($("#effectDate").val() == "") {
//			$("#effectDate").focus();
//			top.$.jBox.tip('合同生效日期不能为空', 'warning');
//			return false;
//		}
//	}
	var isModifyContract = $("#isModifyContract").val();
	if(isModifyContract == "1"){
		if ($("#effectDate").val() == "") {
			$("#effectDate").focus();
			top.$.jBox.tip('合同生效日期不能为空', 'warning');
			return false;
		}
	}
	
	var startDate =$("#startDate").val();
	var endDate =$("#endDate").val();
	if(startDate >= endDate){
		top.$.jBox.tip('意向洽谈中合同终止日期必须大于合同起始日期', 'warning');
		return false;
	}
	
	var flag = checkBrandShop();
	if(flag != true){
		return false;
	}
//	if ($("#benefit").val() == "") {
//		$("#benefit").focus();
//		top.$.jBox.tip('坪效不能为空', 'warning');
//		return false;
//	}
	
//	if ($("#guideType").val() == "") {
//		$("#guideType").focus();
//		top.$.jBox.tip('请选择自派导购', 'warning');
//		return false;
//	}
//	if ($("#guideAmount").val() == "") {
//		$("#guideAmount").focus();
//		top.$.jBox.tip('导购数量不能为空', 'warning');
//		return false;
//	}
//	if ($("#businessType").val() == "") {
//		alert("xx");
//		$("#businessType").focus();
//		top.$.jBox.tip('请选择供应商经营方式', 'warning');
//		return false;
//	}
}

function validataBrand(){
	if ($("#brand").val() == "") {
		$("#brand").focus();
		top.$.jBox.tip('请选择品牌', 'warning');
		return false;
	}
	if ($("#brandAttribute").val() == "") {
		$("#brandAttribute").focus();
		top.$.jBox.tip('请选择品牌属性', 'warning');
		return false;
	}
	if ($("#shopName").val() == "") {
		$("#shopName").focus();
		top.$.jBox.tip('请选择商铺', 'warning');
		return false;
	}
	if ($("#mainBarnd").val() == "") {
		$("#mainBarnd").focus();
		top.$.jBox.tip('请选择是否主品牌', 'warning');
		return false;
	}
	if ($("#memberRateType").val() == "") {
		$("#memberRateType").focus();
		top.$.jBox.tip('请选择会员卡类型', 'warning');
		return false;
	}
	if ($("#memberRateType").val() == "") {
		$("#memberRateType").focus();
		top.$.jBox.tip('请选择会员卡类型', 'warning');
		return false;
	}
}

function validataItems(){
	if ($("#deductCode").val() == "") {
		$("#deductCode").focus();
		top.$.jBox.tip('请选择扣款项代码', 'warning');
		return false;
	}
	if ($("#deductItem").val() == "") {
		$("#deductItem").focus();
		top.$.jBox.tip('扣款项不能为空', 'warning');
		return false;
	}
//	if ($("#deductCate").val() == "") {
//		$("#deductCate").focus();
//		top.$.jBox.tip('请选择扣款类型', 'warning');
//		return false;
//	}
	if ($("#amount").val() == "") {
		$("#amount").focus();
		top.$.jBox.tip('金额/比例不能为空', 'warning');
		return false;
	}
	if ($("#assItemsValidType").val() == "") {
		$("#assItemsValidType").focus();
		top.$.jBox.tip('请选择时效类型', 'warning');
		return false;
	}
//	if ($("#assItemsCountBase").val() == "") {
//		$("#assItemsCountBase").focus();
//		top.$.jBox.tip('请选择计算基数', 'warning');
//		return false;
//	}
//	if ($("#assItemsDeductType").val() == "") {
//		$("#assItemsDeductType").focus();
//		top.$.jBox.tip('请选择扣款方式', 'warning');
//		return false;
//	}
	if ($("#taxRateCode_items").val() == "") {
		$("#taxRateCode_items").focus();
		top.$.jBox.tip('请选择税率', 'warning');
		return false;
	}
	if ($("#assItemsStartDate").val() == "") {
		$("#assItemsStartDate").focus();
		top.$.jBox.tip('开始日期不能为空', 'warning');
		return false;
	}
	if ($("#assItemsEndDate").val() == "") {
		$("#assItemsEndDate").focus();
		top.$.jBox.tip('结束日期不能为空', 'warning');
		return false;
	}
	var startDate =$("#assItemsStartDate").val();
	var endDate =$("#assItemsEndDate").val();
	if(startDate >= endDate){
		top.$.jBox.tip('结束日期必须大于开始日期', 'warning');
		return false;
	}
	if(startDate < $("#startDate").val()){
		top.$.jBox.tip('开始日期不能小于合同起始日期', 'warning');
		return false;
	}
	if(endDate > $("#endDate").val()){
		top.$.jBox.tip('结束期不能大于合同终止日期', 'warning');
		return false;
	}
}

function validataBaseItem(){
	if ($("#brandName").val() == "" || $("#brandName").val() =="0") {
		$("#brandName").focus();
		top.$.jBox.tip('请选择品牌', 'warning');
		return false;
	}
	if ($("#isGuarantee").val() == "") {
		$("#isGuarantee").focus();
		top.$.jBox.tip('请选择是否保底', 'warning');
		return false;
	}
	if ($("#codeType").val() == "") {
		$("#codeType").focus();
		top.$.jBox.tip('请选择销售码类型', 'warning');
		return false;
	}
	if ($("#deductType_base").val() == "") {
		$("#deductType_base").focus();
		top.$.jBox.tip('请选择扣款方式', 'warning');
		return false;
	}
//	if ($("#lower").val() == "") {
//		$("#lower").focus();
//		top.$.jBox.tip('扣款下限不能为空', 'warning');
//		return false;
//	}
//	if ($("#upper").val() == "") {
//		$("#upper").focus();
//		top.$.jBox.tip('扣款上限不能为空', 'warning');
//		return false;
//	}
	if ($("#validType").val() == "") {
		$("#validType").focus();
		top.$.jBox.tip('请选择时效类型', 'warning');
		return false;
	}
	if ($("#deductRate").val() == "") {
		$("#deductRate").focus();
		top.$.jBox.tip('税率不能为空', 'warning');
		return false;
	}
	if ($("#deductRate").val() == "") {
		$("#deductRate").focus();
		top.$.jBox.tip('税率不能为空', 'warning');
		return false;
	}
	if ($("#startDate_base").val() == "") {
		$("#startDate_base").focus();
		top.$.jBox.tip('开始日期不能为空', 'warning');
		return false;
	}
	if ($("#endDate_base").val() == "") {
		$("#endDate_base").focus();
		top.$.jBox.tip('结束日期不能为空', 'warning');
		return false;
	}
	
	if($("#isGuarantee").val() == "1"){		//如果选择是保底。 则需要判断保底形式、保底金额等是否为空
		if ($("#guaranteeType").val() == "") {
			$("#guaranteeType").focus();
			top.$.jBox.tip('请选择保底形式', 'warning');
			return false;
		}
		if ($("#guaranteeAmount").val() == "") {
			$("#guaranteeAmount").focus();
			top.$.jBox.tip('保底金额不能为空', 'warning');
			return false;
		}
		if ($("#iscommGuarantee").val() == "") {
			$("#iscommGuarantee").focus();
			top.$.jBox.tip('请选择是否通用保底', 'warning');
			return false;
		}
		if ($("#countbase_base").val() == "") {
			$("#countbase_base").focus();
			top.$.jBox.tip('请选择促销是否计入保底', 'warning');
			return false;
		}
	}
	var startDate =$("#startDate_base").val();
	var endDate =$("#endDate_base").val();
	
	if(startDate >= endDate){
		top.$.jBox.tip('结束日期必须大于开始日期', 'warning');
		return false;
	}
	if(startDate < $("#startDate").val()){
		top.$.jBox.tip('开始日期不能小于合同起始日期', 'warning');
		return false;
	}
	if(endDate > $("#endDate").val()){
		top.$.jBox.tip('结束期不能大于合同终止日期', 'warning');
		return false;
	}
}

//验证品牌中的铺位是否在签约商铺中存在
function checkBrandShop(){
	var shop = $("#shopIds").val().split(",");
	var flag = false;
	for(var i=0; i<assBrandList.length; i++){
		var brandShop = $("#assShopIds"+assBrandList[i]).val().split(",");
		flag = false;
		for(var j=0; j<shop.length; j++){
			for(var k=0; k<brandShop.length; k++){
				if(brandShop[k] == shop[j]){
					flag = true;
				}
			}
		}
		if(flag == false){
			top.$.jBox.tip('品牌信息中第'+Number(i+1)+'条的铺位不存在', 'warning');
			return flag;
		}
	}
	return flag;
}


/*******************************
 * 税率类型变更
 *******************************/
function taxTypeChange(value, text) {
	var contextPath = Com_Parameter.ContextPath;
	if (value == null || value == "") {
		$("#taxRateCode_select").empty();
	} else {
		$("#taxTypeCode").val(value);
		$("#taxType").val(text);
		$("#taxRateCode_select").FillOptions(
				contextPath + "/biz/contract/commonContract/" + value
						+ "/getTaxRateTypeCode", {
					datatype : "json",
					textfield : "taxRate",
					valuefiled : "taxRateNum",
//					defValue : taxRateCode
				});
		var val = $("#taxRateCode_select").val();
		$("#taxRateCode").val(val);
	}
}

/*******************************
 * 税率变更
 *******************************/
function taxRateCodeChange(value, text) {
	$("#taxRateCode").val(value);
	$("#taxRate").val(text);
}

//页面加载扣款项下拉列表
function loadItems(){
	$("#codeTable > tbody").find("tr").each(
			function() {
				$(this).find("td").each(
					function() {
						var select = $(this).find("select");
						select.each(function() {
							var index = $(this).attr("data_index");
							var kid = 'assTempItemCodeList'+ index+ '.itemCode';
							var did = 'assTempItemCodeList'+ index+ '.conditions';
							if (this.id == kid) {
								var ui = $(this);
								var defValue = ui.attr("data_def");
								ui.FillOptions(contextpath+ "/sys/base/spfItem/getSpecificItems",
								{
									datatype : "json",
									textfield : "itemName",
									valuefiled : "itemNum",
									defValue : ""
									+ defValue
									+ ""
								});
							}
							if (this.id == did) {
								var ui = $(this);
								var defValue = ui.attr("data_def");
								var sptNum = ui.attr("spt_Num");
								ui.FillOptions(
									contextpath
											+ "/sys/base/spfItem/getConditions?sptNum="
											+ defValue,
									{
										datatype : "json",
										textfield : "value",
										valuefiled : "key",
										defValue : ""
												+ defValue
												+ ""
									});
								}
							});
						});
			});
}

//页面加载初始化门店数据
function loadStore(){
	var area = $("#area").val();
	var storeId1 = $("#storeId_hid").val();
	if (area != "" && area != null) {
		var areaId = $("#areaId").val();
		$.get(contextpath + '/biz/contract/commonContract/' + areaId
				+ '/getStoreByAreaId', function(data) {
			var jsonObj = eval('(' + data + ')');
			for (var i = 0; i < jsonObj.length; i++) {
				var shop = jsonObj[i];
				$("#storeId").append("<option value='" + shop.code + "'>" + shop.name+ "</option>");
				$("#storeId").children("option").each(function() {
					if ($(this).val() == storeId1) {
						$(this).attr("selected", "selected");
					}
				});
			}
		});
		$.get(contextpath + '/biz/contract/commonContract/' + storeId1
				+ '/getFloorByStoreId', function(data) {
			var jsonObj = eval('(' + data + ')');
			var floorId1 = $("#floor_hid").val();
			for (var i = 0; i < jsonObj.length; i++) {
				var floor = jsonObj[i];
				$("#floorId").append(
						"<option value='" + floor.code + "'>" + floor.name
								+ "</option>");
				$("#floorId").children("option").each(function() {
					if ($(this).val() == floorId1) {
						$(this).attr("selected", "selected");
					}
				});
			}
		});
	}
	
	var formart = $("#formatId").val();
	$("#formatIdSelect").FillOptions(
			contextpath + "/biz/contract/commonContract/getLoadFormat?storeId="
					+ storeId1, {
				datatype : "json",
				textfield : "name",
				valuefiled : "code",
				defValue : formart
			});
}

//页面加载初始化税率
function loadTaxRateCode(){
	var taxTypeCode = $("#taxTypeCode").val();
	var taxRateCode = $("#taxRateCode").val();
	if (taxTypeCode != null && '' != taxTypeCode) {
		$("#taxRateCode_select").FillOptions(
				contextpath + "/biz/contract/commonContract/" + taxTypeCode
						+ "/getTaxRateTypeCode", {
					datatype : "json",
					textfield : "taxRate",
					valuefiled : "taxRateNum",
					defValue : taxRateCode
				});
	}
}


function changeSelect(id, value) {
	if (id == "#guideType" && value == 1) {
		$('#guideAmount').removeAttr("disabled");
	} else if (id == "#guideType" && value == 0) {
		$('#guideAmount').attr("disabled", "disabled");
	}
	$("" + id + "").val(value);
}

function clickStore(){
	var store = $("#store").val();
	var storeId = $("#storeId_hid").val();
	
	$(this).children("option").each(function() {
		if ($(this).val() == storeId) {
			store = $(this).text();
		}
	});
	
	$.get(contextpath + "/biz/contract/commonContract/" + storeId
			+ "/getFormat", function(data) {
		var jsonObj = eval('(' + data + ')');
		var formatList = jsonObj.formatList;
		$("#formatIdSelect").children("option").each(function() {
			$(this).remove();
		});
		for (var i = 0; i < formatList.length; i++) {
			var format = formatList[i];
			if (i == 0) {
				$("#formatId").val(format.code)
			}
			$("#formatIdSelect").append(
					"<option value='" + format.code + "'>"
							+ format.name + "</option>");
		}
		var code = jsonObj.code;
		var name = jsonObj.name;
		if (name != null) {
			$("#signBodyName").val(name);
		}
		if (code != null) {
			$("#signBody").val(code);
		}
	});
}

function loadSupplier(){
	var id = $("#supplierId").val();
	$.get(contextpath+"/biz/contract/commonContract/"+id+"/getSupplierRegister", function(data){
		var jsonObj =eval('(' + data + ')'); 
		var item = jsonObj.taxType;
		var taxTypeText;
		var taxTypeValue;
		$("#taxTypeCode_select").children("option").each(function(){
			if($(this).val() == item){
				$(this).attr("selected","selected");
				taxTypeText = $(this).text();
				taxTypeValue= $(this).attr("value");
				$("#taxTypeCode").val(taxTypeValue)
				$("#taxType").val(taxTypeText)
			    return false; 
			}else{
				$("#taxTypeCode_select").val('');
				$("#taxTypeCode").val('')
				$("#taxType").val('')
				taxTypeText='NAN'
			}
		});
		$.get(contextpath+"/biz/contract/commonContract/"+taxTypeValue+"/getTaxRateTypeCode",function(data){
			var jsonObj =eval('(' + data + ')'); 
			if(jsonObj.length==0){
				$("#taxRateCode_select").empty(); 
			}
			$("#taxRateCode_select").children("option").each(function(){
				$(this).remove();	
			});
			for(var i = 0 ;i<jsonObj.length;i++){
				var tax = jsonObj[i];
				$("#taxRateCode_select").append("<option value='"+tax.taxRateNum+"'>"+tax.taxRate+"</option>");
				if(i==1){
					$("#taxRateCode").val(tax.taxRateNum);
					$("#taxRate").val(tax.taxRate);
				}
			}
		});
	});
}

function copyTr(index){
	var isGuarantee = $("#isGuarantee"+index).val();
	var lower = $("#lower"+index).val();
	var upper = $("#upper"+index).val();
	var payDate = $("#payDate"+index).val();
	var deductRate = $("#deductRate"+index).val();
	var brandsId = $("#brandsId"+index).val();
	var validType = $("#validType"+index).val();
	var countbase_base = $("#countbase_base"+index).val();
	var guaranteeType = $("#guaranteeType"+index).val();
	var deductType_base = $("#deductType_base"+index).val();
	var startDate_base = $("#startDate_base"+index).val();
	var endDate_base = $("#endDate_base"+index).val();
	var iscommGuarantee = $("#iscommGuarantee"+index).val();
	var guaranteeAmount = $("#guaranteeAmount"+index).val();
	var remarks = $("#remarks"+index).val();
	var codeType = $("#codeType"+index).val();
	var isCompare = $("#isCompare"+index).val();
}

function formtDeductRate(){
	var val = $("#deductRate").val();
	var value = "";
	var spl = val.split(".");
	if(spl.length == 2){
		value = spl[1];
	}
	if(value == ""){
		val = val.replace(".","");
		val += ".000";
	}else if(value.length == 1){
		val += "00";
	}else if(value.length == 2){
		val += "0";
	}else if(value.length > 3){
		val = val.split(".")[0];
		val += "."+value.substring(0,3);
	}
	$("#deductRate").val(val);
}

function clearNoNum(obj)
{
	//先把非数字的都替换掉，除了数字和.
	obj.value = obj.value.replace(/[^\d.]/g,"");
	//必须保证第一个为数字而不是.
	obj.value = obj.value.replace(/^\./g,"");
	//保证只有出现一个.而没有多个.
	obj.value = obj.value.replace(/\.{2,}/g,".");
	//保证.只出现一次，而不能出现两次以上
	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}


function is_bear(id){
	var val = $("input[name='"+id+"']:checked").val();
	if(val == 1){
		$("#"+id+"_div").show();
		if(id+"_div" == "isTraining_div"){
			$("#isTrainingAmount").val("200");
		}else if(id+"_div" == "isJobCard_div"){
			$("#isJobCardAmount").val("20");
		}
	}else{
		$("#"+id+"_div").hide();
		$("#"+id+"Amount").val("");
	}
}

